/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package configuraciones;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import org.cip.esymons.general.be.Permiso;

/**
 *
 * @author Lizardo Rios
 */
public class PermisoConverter implements Converter {

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
        if(arg2 == null){
            return null;
        }
        Integer codigo = new Integer(arg2);
        PermisoController controller = (PermisoController)FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance(), "PermisoController");
        return controller.buscarPorCodigo(codigo);
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
        if (arg2 == null) {
            return null;
        }
        if(arg2 instanceof Permiso){
            return ((Permiso)arg2).getPmsCodigo().toString();
        }else{
            return null;
        }
    }
}
